function t(t) {
    this.selfOpenId = "", this.ctx = t, this.left = 0, this.top = 0, this.width = 1e3, 
    this.height = 1e3, this.sortedRankData = [], this.pagecount = 0, this.pageIndex = 0, 
    this.lastPageIndex = 0, this.myInfo = {}, this.opened = !1, this.scoreFont = "arial";
}

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = t;

var e = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("./utils.js"));

t.prototype.logicHandle = function(t) {
    this.opened = !0;
    var e = this;
    wx.getGroupCloudStorage({
        shareTicket: t.shareTicket,
        keyList: [ "score" ],
        success: function(a) {
            e.sortRankList(a.data), e.drawRankList(t);
        }
    });
}, t.prototype.setOpenId = function(t) {
    if (this.selfOpenId = t, this.opened) {
        if (this.sortedRankData.length <= 0) return;
        this.getMyInfo(), this.drawMyInfo(this.myInfo, this.left, this.top, this.width, 114);
    }
}, t.prototype.sortRankList = function(t) {
    var a = e.default.transRankData(t);
    this.sortedRankData = e.default.quickSortByScore(a);
}, t.prototype.drawMyInfo = function(t, e, a, i, s) {
    if (t.score) {
        var n = 800, o = "50px " + this.scoreFont, r = "70px " + this.scoreFont, h = this.ctx;
        if (t.img) t.loaded || (t.img.onload = function() {
            h.drawImage(t.img, e + 198, a + 40, 110, 110), t.loaded = !0;
        }); else {
            var l = wx.createImage();
            l.src = t.avatarUrl, t.img = l, l.onload = function() {
                h.drawImage(t.img, e + 198, a + 40, 110, 110), t.loaded = !0;
            };
        }
        h.drawImage(t.img, e + 198, a + 40, 110, 110);
        h.fillStyle = "#fff", h.font = r, h.fillText(t.rank, e + 30, a + 115), h.fillStyle = "rgba(150,150,150,0.5)", 
        h.font = "35px Arial", h.fillText(t.nickname, e + 393, a + 105), h.fillStyle = "#fff", 
        h.font = o, n -= h.measureText(t.score.toString()).width, h.fillText(t.score, e + n, a + 115);
    }
}, t.prototype.getMyInfo = function() {
    for (var t = 0; t < this.sortedRankData.length; t++) if (this.selfOpenId === this.sortedRankData[t].openId) {
        this.myInfo.rank = t + 1, this.myInfo.avatarUrl = this.sortedRankData[t].avatarUrl, 
        this.myInfo.nickname = this.sortedRankData[t].nickname, this.myInfo.score = this.sortedRankData[t].score;
        break;
    }
}, t.prototype.drawRankList = function(t) {
    this.getMyInfo();
    this.ctx;
    this.left = t.left, this.top = t.top, this.width = t.width, this.height = t.height;
    var e = this.sortedRankData.length;
    if (!(e <= 0)) {
        this.pageCount = Math.ceil(e / 8), this.pageIndex = 0;
        var a = 8 * this.pageIndex, i = a + 8 - 1;
        i >= e && (i = e - 1), this.drawSinglePage(a, i);
    }
}, t.prototype.drawSinglePage = function(t, a) {
    this.ctx.clearRect(0, 0, e.default.screenWidth, e.default.screenHeight), "" != this.selfOpenId && this.drawMyInfo(this.myInfo, this.left, this.top, this.width, 114);
    for (var i = t; i <= a; i++) {
        var s = this.sortedRankData[i];
        this.drawElement(i, s, this.left, this.top + 114 * (i - t), 940, 114);
    }
}, t.prototype.clear = function() {
    var t = this.sortedRankData.length;
    if (!(t <= 0)) {
        var a = this.ctx;
        if (this.lastPageIndex !== this.PageIndex) {
            var i = 8 * this.pageIndex, s = i + 8 - 1;
            s >= t && (s = t - 1);
            for (var n = i; n < s; n++) {
                var o = this.sortedRankData[n];
                o.img && (o.img.onload = null);
            }
            a.clearRect(0, 0, e.default.screenWidth, e.default.screenHeight);
        }
    }
}, t.prototype.closedClear = function() {
    this.opened = !0;
    var t = this.sortedRankData.length;
    if (!(t <= 0)) {
        var a = this.ctx, i = 8 * this.pageIndex, s = i + 8 - 1;
        s >= t && (s = t - 1);
        for (var n = i; n < s; n++) {
            var o = this.sortedRankData[n];
            o.img && (o.img.onload = null);
        }
        a.clearRect(0, 0, e.default.screenWidth, e.default.screenHeight);
    }
}, t.prototype.drawElement = function(t, e, a, i, s, n) {
    var o = (t < 3 ? "70" : "41") + "px " + this.scoreFont, r = 800, h = "41px " + this.scoreFont, l = this.ctx;
    if (e.img) e.loaded || (e.img.onload = function() {
        l.drawImage(e.img, a + 198, i + 232, 90, 90), e.loaded = !0;
    }); else {
        var f = wx.createImage();
        f.src = e.avatarUrl, e.img = f, f.onload = function() {
            l.drawImage(e.img, a + 198, i + 232, 90, 90), e.loaded = !0;
        };
    }
    var d = "#fff";
    0 === t && (d = "#f6ff03") || 1 === t && (d = "#ff9c00") || 2 === t && (d = "#ff9c00"), 
    l.fillStyle = d, l.font = o, l.fillText(t + 1, a + 30, i + 300), l.drawImage(e.img, a + 198, i + 232, 90, 90), 
    l.fillStyle = "rgba(150,150,150,0.5)", l.font = "29px Arial", l.fillText(e.nickname, a + 393, i + 297), 
    l.fillStyle = "#fff", l.font = h, r -= l.measureText(e.score.toString()).width, 
    l.fillText(e.score, a + r, i + 301);
}, t.prototype.previousPage = function() {
    var t = this.sortedRankData.length;
    if (!(t <= 0 || this.pageIndex <= 0)) {
        this.clear(), this.lasPageIndex = this.pageIndex;
        var e = 8 * --this.pageIndex, a = e + 8 - 1;
        a >= t && (a = t - 1), this.drawSinglePage(e, a);
    }
}, t.prototype.nextPage = function() {
    var t = this.sortedRankData.length;
    if (!(t <= 0 || this.pageIndex >= this.pageCount - 1)) {
        this.clear(), this.lasPageIndex = this.pageIndex;
        var e = 8 * ++this.pageIndex, a = e + 8 - 1;
        a >= t && (a = t - 1), this.drawSinglePage(e, a);
    }
};